package cn.yunhe.action;

import cn.yunhe.entity.Page;
import cn.yunhe.entity.Topic;
import cn.yunhe.service.ITopicService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
@Controller
public class TopicAction extends ActionSupport implements ModelDriven {
    private Topic topic;
    private Page page;
    private int pageSize;
    private int pageNum;
    @Autowired
    private ITopicService topicService;

    @Override
    public String execute() throws Exception {
        Map<String, Object> cond = new HashMap<String, Object>();
        cond.put("pageSize", pageSize);
        cond.put("pageNum", pageNum);
        cond.put("topic", topic);
        page = topicService.queryTopicByPage(cond);
        return SUCCESS;
    }

    @Override
    public Object getModel() {
        if (topic == null) {
            topic = new Topic();
        }
        return topic;
    }
}
